import * as Sequelize from 'sequelize';
import { DataTypes, Model, Optional } from 'sequelize';
import type { FactoryToyItem, FactoryToyItemId } from './FactoryToyItem';

export interface FactoryToyManualAttributes {
  id: string;
  toyId: string;
  title: string;
  type?: string;
  version?: string;
  content?: string;
  fileUrl?: string;
  language?: string;
  createdTime: Date;
  updatedTime: Date;
}

export type FactoryToyManualPk = 'id';
export type FactoryToyManualId = FactoryToyManual[FactoryToyManualPk];
export type FactoryToyManualOptionalAttributes =
  | 'type'
  | 'version'
  | 'content'
  | 'fileUrl'
  | 'language'
  | 'createdTime'
  | 'updatedTime';
export type FactoryToyManualCreationAttributes = Optional<
  FactoryToyManualAttributes,
  FactoryToyManualOptionalAttributes
>;

export class FactoryToyManual
  extends Model<FactoryToyManualAttributes, FactoryToyManualCreationAttributes>
  implements FactoryToyManualAttributes
{
  id!: string;
  toyId!: string;
  title!: string;
  type?: string;
  version?: string;
  content?: string;
  fileUrl?: string;
  language?: string;
  createdTime!: Date;
  updatedTime!: Date;

  // FactoryToyManual belongsTo FactoryToyItem via toyId
  toy!: FactoryToyItem;
  getToy!: Sequelize.BelongsToGetAssociationMixin<FactoryToyItem>;
  setToy!: Sequelize.BelongsToSetAssociationMixin<
    FactoryToyItem,
    FactoryToyItemId
  >;
  createToy!: Sequelize.BelongsToCreateAssociationMixin<FactoryToyItem>;

  static initModel(sequelize: Sequelize.Sequelize): typeof FactoryToyManual {
    return FactoryToyManual.init(
      {
        id: {
          type: DataTypes.CHAR(36),
          allowNull: false,
          primaryKey: true,
          comment: '雪花主键',
        },
        toyId: {
          type: DataTypes.CHAR(36),
          allowNull: false,
          comment: '所属玩具ID',
          references: {
            model: 'factory_toy_item',
            key: 'id',
          },
          field: 'toy_id',
        },
        title: {
          type: DataTypes.STRING(255),
          allowNull: false,
          comment: '说明书标题',
        },
        type: {
          type: DataTypes.STRING(50),
          allowNull: true,
          comment: '说明书类型，如安装、安全等',
        },
        version: {
          type: DataTypes.STRING(50),
          allowNull: true,
          comment: '说明书版本号',
        },
        content: {
          type: DataTypes.TEXT,
          allowNull: true,
          comment: '说明书富文本内容',
        },
        fileUrl: {
          type: DataTypes.STRING(512),
          allowNull: true,
          comment: '附件URL',
          field: 'file_url',
        },
        language: {
          type: DataTypes.STRING(20),
          allowNull: true,
          defaultValue: 'zh-CN',
          comment: '语言标识',
        },
        createdTime: {
          type: DataTypes.DATE,
          allowNull: false,
          defaultValue: Sequelize.Sequelize.literal('CURRENT_TIMESTAMP'),
          comment: '创建时间',
          field: 'created_time',
        },
        updatedTime: {
          type: DataTypes.DATE,
          allowNull: false,
          defaultValue: Sequelize.Sequelize.literal('CURRENT_TIMESTAMP'),
          comment: '更新时间',
          field: 'updated_time',
        },
      },
      {
        sequelize,
        tableName: 'factory_toy_manual',
        timestamps: false,
        indexes: [
          {
            name: 'PRIMARY',
            unique: true,
            using: 'BTREE',
            fields: [{ name: 'id' }],
          },
          {
            name: 'idx_factory_toy_manual',
            using: 'BTREE',
            fields: [{ name: 'id' }],
          },
          {
            name: 'fk_factory_toy_manual',
            using: 'BTREE',
            fields: [{ name: 'toy_id' }],
          },
        ],
      },
    );
  }
}
